'''
# coding=utf-8
@Author: your name
@Date: 2020-06-04 15:58:28
@LastEditTime: 2020-06-04 17:24:23
@LastEditors: Please set LastEditors
@Description: 处理识别错误的结果
@FilePath: /mtl-text-recognition/False_Ano.py
'''

def open_txt(file_name):
    with open(file_name, 'r') as f:
        try:
            line = f.readline()
            while line:
                yield line.strip()
                line = f.readline()
        except:
            print('No value')

txt_file = 'saved_models/5_26_id_VGG_bilstm256_CTC_1T_BL/id_annotations.txt'
false_out = open('saved_models/5_26_id_VGG_bilstm256_CTC_1T_BL/false.txt', 'w')
count_all = 0
count_right = 0
for line in open_txt(txt_file):
    gt, label = line.split(',')[8].strip(), line.split(',')[10].strip()
    
    if len(label) > 0 and label[-1] == 'x':
         label = label[:-1] + 'X'
    if gt ==  ''.join(label.split('.')).strip() or gt == label:
        count_right += 1
    else:
        false_out.writelines(gt.strip() + ',' + label + '\n')
    count_all += 1
print(count_right / count_all)